package org.cloudlab.controller;

import org.cloudlab.bean.AcademicJournal;
import org.cloudlab.common.ResponseResult;
import org.cloudlab.service.IAcademicJournalService;
import org.cloudlab.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Liu Yicong
 * @date 2023/9/3
 */
@RestController
public class HelloController {

    @Autowired
    private IAcademicJournalService journalService;

    @Autowired
    private RedisCache redis;

    @RequestMapping("/hello")
    public String hello() {
        return "hello" + redis.getCacheObject("123");
    }

    @GetMapping(value = "/addJournal/{name}")
    public ResponseResult<String> addJournal(@PathVariable(value = "name") String name) {
        try {
            AcademicJournal academicJournal = new AcademicJournal();
            academicJournal.setJournalName(name);
            academicJournal.setCAS("1,1,TOP");
            academicJournal.setJCR("Q1");
            journalService.save(academicJournal);
        } catch (Exception e) {
            return ResponseResult.fail(e.getMessage());
        }

        return ResponseResult.success("添加成功");
    }
}
